﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using PS.DBUtility;
namespace PS.DAL
{
    /// <summary>
    /// 数据访问类:RepProjectInfo
    /// </summary>
    public partial class RepProjectInfo
    {
        public RepProjectInfo()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录

        /// </summary>
        public bool Exists(int RepProjectInfoID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from RepProjectInfo");
            strSql.Append(" where RepProjectInfoID=@RepProjectInfoID");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4)
};
            parameters[0].Value = RepProjectInfoID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据

        /// </summary>
        public int Add(PS.Model.RepProjectInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into RepProjectInfo(");
            strSql.Append("ProjectName,ProjectID,ProjectPrincipal,ProjectType,StartDate,FinishDate,ConstructDepID,Memo,Creator,CreateTime,Editor,EditTime,DispOrder,ValidMark,Spare1,Spare2,Spare3,Spare4,ProjectProgress,ProjectWorkAmount,SpareDecimal5,SpareDecimal6,SpareDecimal7,SpareDecimal8,PlanFinishDate,ConstructPlace)");
            strSql.Append(" values (");
            strSql.Append("@ProjectName,@ProjectID,@ProjectPrincipal,@ProjectType,@StartDate,@FinishDate,@ConstructDepID,@Memo,@Creator,@CreateTime,@Editor,@EditTime,@DispOrder,@ValidMark,@Spare1,@Spare2,@Spare3,@Spare4,@ProjectProgress,@ProjectWorkAmount,@SpareDecimal5,@SpareDecimal6,@SpareDecimal7,@SpareDecimal8,@PlanFinishDate,@ConstructPlace )");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@ProjectName", SqlDbType.VarChar,100),
					new SqlParameter("@ProjectID", SqlDbType.VarChar,30),
					new SqlParameter("@ProjectPrincipal", SqlDbType.Int,4),
					new SqlParameter("@ProjectType", SqlDbType.Int,4),
					new SqlParameter("@StartDate", SqlDbType.DateTime),
					new SqlParameter("@FinishDate", SqlDbType.DateTime),
					new SqlParameter("@ConstructDepID", SqlDbType.VarChar,200),
					new SqlParameter("@Memo", SqlDbType.VarChar,2000),
					new SqlParameter("@Creator", SqlDbType.VarChar,20),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@Editor", SqlDbType.VarChar,20),
					new SqlParameter("@EditTime", SqlDbType.DateTime),
					new SqlParameter("@DispOrder", SqlDbType.Int,4),
					new SqlParameter("@ValidMark", SqlDbType.Int,4),
					new SqlParameter("@Spare1", SqlDbType.VarChar,200),
					new SqlParameter("@Spare2", SqlDbType.VarChar,200),
					new SqlParameter("@Spare3", SqlDbType.VarChar,200),
					new SqlParameter("@Spare4", SqlDbType.VarChar,200),
					new SqlParameter("@ProjectProgress", SqlDbType.VarChar,100),
					new SqlParameter("@ProjectWorkAmount", SqlDbType.VarChar,100),
					new SqlParameter("@SpareDecimal5", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal6", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal7", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal8", SqlDbType.Decimal,9),
                    new SqlParameter("@PlanFinishDate", SqlDbType.DateTime) , 
                    new SqlParameter("@ConstructPlace", SqlDbType.VarChar,100)};

            parameters[0].Value = model.ProjectName;
            parameters[1].Value = model.ProjectID;
            parameters[2].Value = model.ProjectPrincipal;
            parameters[3].Value = model.ProjectType;
            parameters[4].Value = model.StartDate;
            parameters[5].Value = model.FinishDate;
            parameters[6].Value = model.ConstructDepID;
            parameters[7].Value = model.Memo;
            parameters[8].Value = model.Creator;
            parameters[9].Value = model.CreateTime;
            parameters[10].Value = model.Editor;
            parameters[11].Value = model.EditTime;
            parameters[12].Value = model.DispOrder;
            parameters[13].Value = model.ValidMark;
            parameters[14].Value = model.Spare1;
            parameters[15].Value = model.Spare2;
            parameters[16].Value = model.Spare3;
            parameters[17].Value = model.Spare4;
            parameters[18].Value = model.ProjectProgress;
            parameters[19].Value = model.ProjectWorkAmount;
            parameters[20].Value = model.SpareDecimal5;
            parameters[21].Value = model.SpareDecimal6;
            parameters[22].Value = model.SpareDecimal7;
            parameters[23].Value = model.SpareDecimal8;
            parameters[24].Value = model.PlanFinishDate;
            parameters[25].Value = model.ConstructPlace;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据

        /// </summary>
        public bool Update(PS.Model.RepProjectInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update RepProjectInfo set ");
            strSql.Append("ProjectName=@ProjectName,");
            strSql.Append("ProjectID=@ProjectID,");
            strSql.Append("ProjectPrincipal=@ProjectPrincipal,");
            strSql.Append("ProjectType=@ProjectType,");
            strSql.Append("StartDate=@StartDate,");
            strSql.Append("FinishDate=@FinishDate,");
            strSql.Append("ConstructDepID=@ConstructDepID,");
            strSql.Append("Memo=@Memo,");
            strSql.Append("Creator=@Creator,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("Editor=@Editor,");
            strSql.Append("EditTime=@EditTime,");
            strSql.Append("DispOrder=@DispOrder,");
            strSql.Append("ValidMark=@ValidMark,");
            strSql.Append("Spare1=@Spare1,");
            strSql.Append("Spare2=@Spare2,");
            strSql.Append("Spare3=@Spare3,");
            strSql.Append("Spare4=@Spare4,");
            strSql.Append("ProjectProgress=@ProjectProgress,");
            strSql.Append("ProjectWorkAmount=@ProjectWorkAmount,");
            strSql.Append("SpareDecimal5=@SpareDecimal5,");
            strSql.Append("SpareDecimal6=@SpareDecimal6,");
            strSql.Append("SpareDecimal7=@SpareDecimal7,");
            strSql.Append("SpareDecimal8=@SpareDecimal8,");
            strSql.Append("PlanFinishDate=@PlanFinishDate,");
            strSql.Append("ConstructPlace=@ConstructPlace");
 
            strSql.Append(" where RepProjectInfoID=@RepProjectInfoID");
            SqlParameter[] parameters = {
					new SqlParameter("@ProjectName", SqlDbType.VarChar,100),
					new SqlParameter("@ProjectID", SqlDbType.VarChar,30),
					new SqlParameter("@ProjectPrincipal", SqlDbType.Int,4),
					new SqlParameter("@ProjectType", SqlDbType.Int,4),
					new SqlParameter("@StartDate", SqlDbType.DateTime),
					new SqlParameter("@FinishDate", SqlDbType.DateTime),
					new SqlParameter("@ConstructDepID", SqlDbType.VarChar,200),
					new SqlParameter("@Memo", SqlDbType.VarChar,2000),
					new SqlParameter("@Creator", SqlDbType.VarChar,20),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@Editor", SqlDbType.VarChar,20),
					new SqlParameter("@EditTime", SqlDbType.DateTime),
					new SqlParameter("@DispOrder", SqlDbType.Int,4),
					new SqlParameter("@ValidMark", SqlDbType.Int,4),
					new SqlParameter("@Spare1", SqlDbType.VarChar,200),
					new SqlParameter("@Spare2", SqlDbType.VarChar,200),
					new SqlParameter("@Spare3", SqlDbType.VarChar,200),
					new SqlParameter("@Spare4", SqlDbType.VarChar,200),
					new SqlParameter("@ProjectProgress", SqlDbType.VarChar,100),
					new SqlParameter("@ProjectWorkAmount", SqlDbType.VarChar,100),
					new SqlParameter("@SpareDecimal5", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal6", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal7", SqlDbType.Decimal,9),
					new SqlParameter("@SpareDecimal8", SqlDbType.Decimal,9),
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4),
                    new SqlParameter("@PlanFinishDate", SqlDbType.DateTime) , 
                    new SqlParameter("@ConstructPlace", SqlDbType.VarChar,100)  };
            parameters[0].Value = model.ProjectName;
            parameters[1].Value = model.ProjectID;
            parameters[2].Value = model.ProjectPrincipal;
            parameters[3].Value = model.ProjectType;
            parameters[4].Value = model.StartDate;
            parameters[5].Value = model.FinishDate;
            parameters[6].Value = model.ConstructDepID;
            parameters[7].Value = model.Memo;
            parameters[8].Value = model.Creator;
            parameters[9].Value = model.CreateTime;
            parameters[10].Value = model.Editor;
            parameters[11].Value = model.EditTime;
            parameters[12].Value = model.DispOrder;
            parameters[13].Value = model.ValidMark;
            parameters[14].Value = model.Spare1;
            parameters[15].Value = model.Spare2;
            parameters[16].Value = model.Spare3;
            parameters[17].Value = model.Spare4;
            parameters[18].Value = model.ProjectProgress;
            parameters[19].Value = model.ProjectWorkAmount;
            parameters[20].Value = model.SpareDecimal5;
            parameters[21].Value = model.SpareDecimal6;
            parameters[22].Value = model.SpareDecimal7;
            parameters[23].Value = model.SpareDecimal8;
            parameters[24].Value = model.RepProjectInfoID;
            parameters[25].Value = model.PlanFinishDate;
            parameters[26].Value = model.ConstructPlace;


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据

        /// </summary>
        public bool Delete(int RepProjectInfoID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from RepProjectInfo ");
            strSql.Append(" where RepProjectInfoID=@RepProjectInfoID");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4)
            };
            parameters[0].Value = RepProjectInfoID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 假删除一条数据

        /// </summary>
        public bool DeleteFalse(int RepProjectInfoID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update RepProjectInfo set ValidMark=0");
            strSql.Append(" where RepProjectInfoID=@RepProjectInfoID");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4)
};
            parameters[0].Value = RepProjectInfoID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据

        /// </summary>
        public bool DeleteList(string RepProjectInfoIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from RepProjectInfo ");
            strSql.Append(" where RepProjectInfoID in (" + RepProjectInfoIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体

        /// </summary>
        public PS.Model.RepProjectInfo GetModel(int RepProjectInfoID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.RepProjectInfoID,'<a href=\"ProjectInfoDetail.aspx?RepProjectInfoID='+cast(RepProjectInfoID As varchar)+'\" target=\"_blank\">' + a.ProjectName + '</a>' as ProjectNameUrl,a.ProjectName,a.ProjectID,c.SubKeyName,a.ProjectPrincipal,b.PersonName,a.ProjectType,a.ConstructDepID,CONVERT(varchar(100), a.StartDate, 23) as StartDate,CONVERT(varchar(100),a. FinishDate, 23) as FinishDate,a.Memo,a.ProjectProgress as ProjectProgress,a.ProjectWorkAmount, case when convert(decimal,a.ProjectWorkAmount) >0 then convert(decimal(10,2), CAST((convert(decimal(12,2),a.ProjectProgress) /100 * convert(decimal(12,2),a.ProjectWorkAmount))  as decimal(12,2)))  else '0' end as ProjectWorkedAmount,a.Creator,a.CreateTime,a.Editor,a.EditTime,a.DispOrder,a.validmark,a.Spare1,a.Spare2,a.Spare3,a.Spare4,a.SpareDecimal5,a.SpareDecimal6,a.SpareDecimal7,a.SpareDecimal8,a.PlanFinishDate,a.ConstructPlace  FROM RepProjectInfo a left join EmpPersonBase b on a.ProjectPrincipal=b.PersonID left join dbo.SysDictionarySub c on a.ProjectType=c.ID where c.MainKeyID=16 and a.validmark=1 and a.RepProjectInfoID=@RepProjectInfoID");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4)
            };
            parameters[0].Value = RepProjectInfoID;

            PS.Model.RepProjectInfo model = new PS.Model.RepProjectInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["RepProjectInfoID"].ToString() != "")
                {
                    model.RepProjectInfoID = int.Parse(ds.Tables[0].Rows[0]["RepProjectInfoID"].ToString());
                }
                model.ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString();
                model.ProjectID = ds.Tables[0].Rows[0]["ProjectID"].ToString();
                if (ds.Tables[0].Rows[0]["ProjectPrincipal"].ToString() != "")
                {
                    model.ProjectPrincipal = int.Parse(ds.Tables[0].Rows[0]["ProjectPrincipal"].ToString());
                    model.Spare1 = ds.Tables[0].Rows[0]["PersonName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ProjectType"].ToString() != "")
                {
                    model.ProjectType = int.Parse(ds.Tables[0].Rows[0]["ProjectType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StartDate"].ToString() != "")
                {
                    model.StartDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["StartDate"].ToString());
                }
                else
                {
                    model.StartDate = null;
                }
                if (ds.Tables[0].Rows[0]["FinishDate"].ToString() != "")
                {
                    model.FinishDate = DateTime.Parse(ds.Tables[0].Rows[0]["FinishDate"].ToString());
                }
                else
                {
                    model.FinishDate = null;
                }
                if (ds.Tables[0].Rows[0]["ConstructDepID"].ToString() != "")
                {
                    model.ConstructDepID = ds.Tables[0].Rows[0]["ConstructDepID"].ToString();
                }
                model.Memo = ds.Tables[0].Rows[0]["Memo"].ToString();

                model.Creator = ds.Tables[0].Rows[0]["Creator"].ToString();
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                model.Editor = ds.Tables[0].Rows[0]["Editor"].ToString();
                if (ds.Tables[0].Rows[0]["EditTime"].ToString() != "")
                {
                    model.EditTime = DateTime.Parse(ds.Tables[0].Rows[0]["EditTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DispOrder"].ToString() != "")
                {
                    model.DispOrder = int.Parse(ds.Tables[0].Rows[0]["DispOrder"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ValidMark"].ToString() != "")
                {
                    model.ValidMark = int.Parse(ds.Tables[0].Rows[0]["ValidMark"].ToString());
                }
                model.Spare1 = ds.Tables[0].Rows[0]["Spare1"].ToString();
                model.Spare2 = ds.Tables[0].Rows[0]["Spare2"].ToString();
                model.Spare3 = ds.Tables[0].Rows[0]["Spare3"].ToString();
                model.Spare4 = ds.Tables[0].Rows[0]["PersonName"].ToString();

                model.ProjectProgress = ds.Tables[0].Rows[0]["ProjectProgress"].ToString();
                model.ProjectWorkAmount = ds.Tables[0].Rows[0]["ProjectWorkAmount"].ToString();

                if (ds.Tables[0].Rows[0]["SpareDecimal5"].ToString() != "")
                {
                    model.SpareDecimal5 = decimal.Parse(ds.Tables[0].Rows[0]["SpareDecimal5"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SpareDecimal6"].ToString() != "")
                {
                    model.SpareDecimal6 = decimal.Parse(ds.Tables[0].Rows[0]["SpareDecimal6"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SpareDecimal7"].ToString() != "")
                {
                    model.SpareDecimal7 = decimal.Parse(ds.Tables[0].Rows[0]["SpareDecimal7"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SpareDecimal8"].ToString() != "")
                {
                    model.SpareDecimal8 = decimal.Parse(ds.Tables[0].Rows[0]["SpareDecimal8"].ToString());
                }

                if (ds.Tables[0].Rows[0]["PlanFinishDate"].ToString() != "")
                {
                    model.PlanFinishDate = DateTime.Parse(ds.Tables[0].Rows[0]["PlanFinishDate"].ToString());
                }
                model.ConstructPlace = ds.Tables[0].Rows[0]["ConstructPlace"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.PlanFinishDate,a.ConstructPlace,a.RepProjectInfoID,'<a href=\"ProjectInfoDetail.aspx?RepProjectInfoID='+cast(RepProjectInfoID As varchar)+'\" target=\"_blank\">' + a.ProjectName + '</a>' as ProjectName,a.ProjectID,c.SubKeyName,a.ProjectPrincipal,b.PersonName,a.ProjectType,a.ConstructDepID,CONVERT(varchar(100), a.StartDate, 23) as StartDate,CONVERT(varchar(100),a. FinishDate, 23) as FinishDate,a.Memo,a.ProjectProgress as ProjectProgress,a.ProjectWorkAmount, case when convert(decimal,a.ProjectWorkAmount) >0 then convert(decimal(10,2), CAST((convert(decimal(12,2),a.ProjectProgress) /100 * convert(decimal(12,2),a.ProjectWorkAmount))  as decimal(12,2)))  else '0' end as ProjectWorkedAmount  FROM RepProjectInfo a left join EmpPersonBase b on a.ProjectPrincipal=b.PersonID left join dbo.SysDictionarySub c on a.ProjectType=c.ID where c.MainKeyID=16 and a.validmark=1  ");
            //strSql.Append(" FROM RepProjectInfo where validmark=1 ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据

        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append("   PlanFinishDate, ConstructPlace,RepProjectInfoID,ProjectName,ProjectID,ProjectPrincipal,ProjectType,StartDate,FinishDate,ConstructDepID,Memo,Creator,CreateTime,Editor,EditTime,DispOrder,ValidMark,Spare1,Spare2,Spare3,Spare4,ProjectProgress as ProjectProgress,ProjectWorkAmount, case when convert(decimal,a.ProjectWorkAmount) >0 then convert(decimal(10,2), CAST((convert(decimal(12,2),a.ProjectProgress) /100 * convert(decimal(12,2),a.ProjectWorkAmount))  as decimal(12,2)))  else '0' end as ProjectWorkedAmount ,SpareDecimal5,SpareDecimal6,SpareDecimal7,SpareDecimal8 ");
            strSql.Append(" FROM RepProjectInfo where a.validmark=1 ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string ProjectName, string ProjectID, string ProjectPrincipal, string ProjectType, string StartDate, string FinishDate, long pageSize, long pageIndex, out long totalCount)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  CONVERT(varchar(100),a. PlanFinishDate, 23) as PlanFinishDate ,a.ConstructPlace,a.RepProjectInfoID,'<a href=\"ProjectInfoDetail.aspx?RepProjectInfoID='+cast(RepProjectInfoID As varchar)+'\" target=\"_blank\">' + a.ProjectName + '</a>' as ProjectName,a.ProjectID,c.SubKeyName,a.ProjectPrincipal,b.PersonName,a.ProjectType,a.ConstructDepID,CONVERT(varchar(100), a.StartDate, 23) as StartDate,CONVERT(varchar(100),a. FinishDate, 23) as FinishDate,ProjectStatus=case when FinishDate is null then '未完成' else '已完成' end,a.Memo,a.ProjectProgress as ProjectProgress,a.ProjectWorkAmount, case when convert(decimal,a.ProjectWorkAmount) >0 then convert(decimal(10,2), CAST((convert(decimal(12,2),a.ProjectProgress) /100 * convert(decimal(12,2),a.ProjectWorkAmount))  as decimal(12,2)))  else '0' end as ProjectWorkedAmount  FROM RepProjectInfo a left join EmpPersonBase b on a.ProjectPrincipal=b.PersonID left join dbo.SysDictionarySub c on a.ProjectType=c.ID where c.MainKeyID=16 and a.validmark=1 ");

            // strSql.Append("select RepProjectInfoID,ProjectName,ProjectID,ProjectPrincipal,ProjectType,StartDate,FinishDate,Memo ");
            // strSql.Append(" FROM RepProjectInfo ");


            StringBuilder strSqlCondition = new StringBuilder();
            //strSqlCondition.Append(" Where 1=1 ");
            if (!string.IsNullOrEmpty(StartDate) && !string.IsNullOrEmpty(FinishDate))
            {
                strSqlCondition.Append(" and  a.StartDate  BETWEEN  '").Append(Convert.ToDateTime(StartDate)).Append("'  and '").Append(Convert.ToDateTime(FinishDate)).Append("'");
            }
            else
            {
                if (!string.IsNullOrEmpty(StartDate))
                {
                    strSqlCondition.Append(" and  a.StartDate   >=  '").Append(StartDate).Append("'");
                }
                if (!string.IsNullOrEmpty(FinishDate))
                {
                    strSqlCondition.Append(" and  a.FinishDate   <=  '").Append(FinishDate).Append("'");
                }
            }

            if (!string.IsNullOrEmpty(ProjectName))
            {

                strSqlCondition.Append(" and a.ProjectName like '%").Append(ProjectName).Append("%'");
            }

            if (!string.IsNullOrEmpty(ProjectID))
            {
                strSqlCondition.Append(" and a.ProjectID ='").Append(ProjectID).Append("'");
            }

            if (!string.IsNullOrEmpty(ProjectPrincipal))
            {
                strSqlCondition.Append(" and a.ProjectPrincipal like '%").Append(ProjectPrincipal).Append("%'");
            }
            if (!string.IsNullOrEmpty(ProjectType))
            {
                strSqlCondition.Append(" and a.ProjectType like '%").Append(ProjectType).Append("%'");
            }

            strSql.Append(strSqlCondition);

            strSql.Append("  order by a.RepProjectInfoID desc");

            string totalSql = PageSplitHelper.GetTotalSql(strSql.ToString());
            totalCount = long.Parse(DbHelperSQL.ExecuteScalar(totalSql).ToString());

            string pageSql = PageSplitHelper.GetPageSql(strSql.ToString(), pageSize, pageIndex, totalCount);
            return DbHelperSQL.Query(pageSql);
        }

        /*
         <summary>
         分页获取数据列表
         </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "RepProjectInfo";
            parameters[1].Value = "RepProjectInfoID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

